package com.dc.aimc.common.service.response;

import lombok.Data;

import java.io.Serializable;

/**
 * JSON响应对象
 */
@Data
public class JsonResponse<T> implements Serializable {

    /**
     * 响应状态码
     */
    private Integer code;

    /**
     * 响应说明
     */
    private String msg;

    /**
     * 响应数据
     */
    private T data;

    public JsonResponse() {
    }

    public JsonResponse(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public JsonResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static<T> JsonResponse<T> success() {
        return new JsonResponse<>(200, "成功", null);
    }

    public static<T> JsonResponse<T> success(T data) {
        return new JsonResponse<>(200, "成功", data);
    }

    public static<T> JsonResponse<T> fail() {
        return new JsonResponse<>(500, "失败", null);
    }

    public static<T> JsonResponse<T> fail(T data) {
        return new JsonResponse<>(500, "失败", data);
    }

    public static<T> JsonResponse<T> fail(Integer code, String msg) {
        return new JsonResponse<>(code, msg, null);
    }

    public static<T> JsonResponse<T> ail(Integer code, String msg, T data) {
        return new JsonResponse<>(code, msg, data);
    }

}
